<?php

include_once("../service/introductionService.php");
include_once("../service/imageService.php");

$result = getAllIntroduction();
$row = ConnectionManager::getInstance()->getNumRows();
if ($row == 0) {
    $name = $_POST["content"];

    $img1 = $_FILES['img1'];
    $img2 = $_FILES['img2'];
    $img3 = $_FILES['img3'];
    $img4 = $_FILES['img4'];
    $img5 = $_FILES['img5'];
    
    uploadIntroductionImage($img1, "1");
    uploadIntroductionImage($img2, "2");
    uploadIntroductionImage($img3, "3");
    uploadIntroductionImage($img4, "4");
    uploadIntroductionImage($img5, "5");
    
    addIntroduction($name);
	$row = getFirstRowOfIntroduction();
	$result = ConnectionManager::getInstance()->fetchArray();
	$id = $result['INT_ID'];
    Header("Location: ../admin-page/introductionDetail.php?message=ok&id=$id");
    return;
} else {
    Header("Location: ../admin-page/introductionDetail.php?message=error");
    return;
}
?>
